/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.netcracker.test.eleven;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author I
 */
public class DeadLock {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        final Object lock1 = new Object();
        final Object lock2 = new Object();
        Thread t1 = new Thread("PrintLock1") {
        @Override
        public void run() {
            synchronized (lock1) {
            try {
                Thread.sleep(1000);
            } catch (Throwable ignored) {
            }
            synchronized (lock2) {
                try {
                Thread.sleep(1000);
                } catch (Throwable ignored) {
                }
                lock2.notify();
            }
            lock1.notify();
            }
        }
        };
        Thread t2 = new Thread("PrintLock2") {
            @Override
        public void run() {
            synchronized (lock2) {
            try {
                Thread.sleep(1000);
            } catch (Throwable ignored) {
            }
            synchronized (lock1) {
                try {
                Thread.sleep(1000);
                } catch (Throwable ignored) {
                }
                lock1.notify();
            }
            lock2.notify();
            }
        }
        };
        t1.start();
        t2.start();
    }
}
